<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Symbol.species</title>
</head>
<body>
<script>
  /*
  * Array.prototype.map是如何实现的
  *
  * */

  Array.prototype.myMap =function(fn){
    let arr = []
    for (let i = 0; i < this.length; i++) {
      arr[i] = fn(this[i],i)
    }
    return arr
  }

 let newArr = [2,1,3,4,5].myMap(item =>item+1)
  console.log(newArr);



  class Dog {
    constructor() {
      this.name = 'A'
    }

    getDog(){
      //实例方法要访问静态要借助constructor因为静态定义在类对象中也就是定义在构造方法上
      //同理静态访问实例要使用this.prototype，但是这么做访问的是原型方法 无法访问到实例属性
      return new this.constructor[Symbol.species]
    }
  }

  class MyDog extends Dog{

    static  get [Symbol.species](){
      return Dog
    }

    getMyDog(){
      console.log('getMyDog');
    }



  }

  let mydog = new MyDog()
  mydog.getMyDog()
  let res = mydog.getDog()
  res.getMyDog()
  console.log(res);
  console.log(res instanceof MyDog);
  console.log(res instanceof Dog);


  console.log('-----------');

  let dog = new Dog()
  console.log(dog.getDog());

</script>
</body>
</html>